package cn.com.cetccst.mdmdemo.doubleApn;

import android.content.Context;

import com.hihonor.android.app.admin.DeviceNetworkManager;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

public class DoubleApnManager {
    private DeviceNetworkManager mDevNetMgr = null;
    private static DoubleApnOpt doubleApnOptInstance;

    public static void init(Context context) {
        try {
            if (doubleApnOptInstance == null) {
                doubleApnOptInstance = new DoubleApnOpt(context);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static HashMap<String, String> ChinaTelecomApnInfo = new HashMap<String, String>() {{
        put("name", "AHJWChinaTelecom");
        put("apn", "public.vpdn");
        put("user", "ahjcw@ahjcw.vpdn.ah");
        put("password", "jcw20210701");
        put("authtype", "2");
        put("mcc", "460");
        put("mnc", "03");
        put("type", "cbs");
        put("protocol", "IPV4V6");
        put("roaming_protocol", "IPV4V6");
    }};
    public static HashMap<String, String> ChinaMobileApnInfo0 = new HashMap<String, String>() {{
        put("name", "AHJWChinaMobile0");
        put("apn", "ahjjjc.ah");
        put("user", "ahjw");
        put("password", "ahjw@2021");
        put("authtype", "1");
        put("mcc", "460");
        put("mnc", "00");
        put("type", "cbs");
        put("protocol", "IPV4V6");
        put("roaming_protocol", "IPV4V6");
    }};
    public static HashMap<String, String> ChinaMobileApnInfo2 = new HashMap<String, String>() {{
        put("name", "AHJWChinaMobile2");
        put("apn", "ahjjjc.ah");
        put("user", "ahjw");
        put("password", "ahjw@2021");
        put("authtype", "1");
        put("mcc", "460");
        put("mnc", "02");
        put("type", "cbs");
        put("protocol", "IPV4V6");
        put("roaming_protocol", "IPV4V6");
    }};
    public static HashMap<String, String> ChinaMobileApnInfo7 = new HashMap<String, String>() {{
        put("name", "AHJWChinaMobile7");
        put("apn", "ahjjjc.ah");
        put("user", "ahjw");
        put("password", "ahjw@2021");
        put("authtype", "1");
        put("mcc", "460");
        put("mnc", "07");
        put("type", "cbs");
        put("protocol", "IPV4V6");
        put("roaming_protocol", "IPV4V6");
    }};
    public static List<HashMap<String, String>> apnInfoList = new ArrayList(Arrays.asList(ChinaTelecomApnInfo, ChinaMobileApnInfo0, ChinaMobileApnInfo7, ChinaMobileApnInfo2));


    public static void handleAddApn() {
        for (HashMap<String, String> apnInfo : apnInfoList) {
            doubleApnOptInstance.addApn(apnInfo);
        }
    }

    public static void handleDelApn() {
        for (HashMap<String, String> apnInfo : apnInfoList) {
            doubleApnOptInstance.delApn(apnInfo.get("apn"));
        }
    }

    public static void handleQueryApn() {
        for (HashMap<String, String> apnInfo : apnInfoList) {
            doubleApnOptInstance.queryApn(apnInfo);
        }
    }

    public static void activeApn(int getuid) {
        String uid = String.valueOf(getuid);
        for (HashMap<String, String> apnInfo : apnInfoList) {
            doubleApnOptInstance.activeApn(uid, apnInfo.get("name"));
        }
    }

    public static void handleSetDefaultApn(int getuid) {
        String uid = String.valueOf(getuid);
        ArrayList<String> pkgList = new ArrayList<>();
        pkgList.add("com.zdk.mg.agent");
        for (HashMap<String, String> apnInfo : apnInfoList) {
            doubleApnOptInstance.setDefaultAPNPkgList(uid, apnInfo.get("name"), pkgList);
        }
    }

    public static void handleClearDefaultApn(int getuid) {
        String uid = String.valueOf(getuid);
        for (HashMap<String, String> apnInfo : apnInfoList) {
            doubleApnOptInstance.clearDefaultApn(uid, apnInfo.get("name"));
        }
    }

    public static void handleQueryDefaultApn(int getuid) {
        String uid = String.valueOf(getuid);
        for (HashMap<String, String> apnInfo : apnInfoList) {
            doubleApnOptInstance.getDefaultAPNPkgList(uid, apnInfo.get("name"));
        }
    }


}
